/**
 * 省市区数据
 */
export interface RegionsData {
    text: string;
    value: string;
    children?: {
        text: string;
        value: string;
        children?: {
            text: string;
            value: string;
        }[];
    }[];
}

/**
 * 获取选中值对应的文本
 * @param values 选中值
 * @param data 省市区数据
 */
export function getValueLabel(values ?: string[], data ?: RegionsData[]) {
    const texts: string[] = [];
    if (values && values.length && data) {
        data.forEach((d) => {
            if (d.value === values[0]) {
                texts.push(d.text);
                if (d.children && d.children.length) {
                    d.children.forEach((c) => {
                        if (c.value === values[1]) {
                            texts.push(c.text);
                        }
                        if (c.children && c.children.length) {
                            c.children.forEach((cc) => {
                                if (cc.value === values[2]) {
                                    texts.push(cc.text);
                                }
                            });
                        }
                    });
                }
            }
        });
    }
    return texts;
}